home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 109_01.zip / UNTAB.C < prev    next >
Text File  |  1993-06-26  |  896b  |  56 lines

  1. /*
  2.     prog to take a text file full of tabs
  3.     and turn them into the right number of spaces:
  4. */
  5.  
  6. #define CR 0x0d
  7. #define LF 0x0a
  8. #define BS 0x08
  9. #define EOF 255
  10. #define CPMEOF 0x1a
  11. #define ERRORCODE -1
  12. #define TAB 0x09
  13.  
  14. char ibuf[134], obuf[134];
  15.  
  16. main(argc,argv)
  17. char **argv;
  18. {
  19.     int fd1, fd2, col;
  20.     char c;
  21.     int i;
  22.     fd1 = fopen(argv[1],ibuf);
  23.     fd2 = fcreat(argv[2],obuf);
  24.     if (fd1 == ERRORCODE || fd2 == ERRORCODE) {
  25.         printf("Open error.\n");
  26.         exit();
  27.     }
  28.     col = 0;
  29.     while ((c=getc(ibuf)) != EOF) {
  30.         switch(c) {
  31.              case CR: col = 0;
  32.             case LF: putc2(c,obuf);
  33.                  continue;
  34.  
  35.             case TAB: do {  
  36.                    putc2(' ',obuf);
  37.                    col++;
  38.                   } while (col%8);
  39.                   continue;
  40.             default:   col++;
  41.          }
  42.         putc2(c,obuf);
  43.      }
  44.     fflush(obuf);
  45.     close(fd1);
  46.     close(fd2);
  47. }
  48.  
  49. putc2(c,obuf)
  50. char c;
  51. {
  52.     putchar(c);
  53.     putc(c,obuf);
  54. }
  55.  
  56.